/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.runtime.component
{
	import com.edi.runtime.Event.EDIEventProxy;
	
	import mx.containers.TitleWindow;
	import mx.controls.TextArea;
	import mx.events.CloseEvent;
	import mx.core.Application;

	/**
	 * 继承自TitleWindow,
	 * 主要用途：消息对话框 
	 * 
	 */	
	public class EDIAlertWindow extends TitleWindow
	{
		private var messageArea:TextArea;
		public function EDIAlertWindow()
		{
			this.setStyle("dropShadowEnabled",true);
			this.setStyle("borderAlpha",1);
			this.setStyle("cornerRadius",0);
			this.width = 400;
			this.height = 300;
			
			this.title = "提示";
			this.showCloseButton=true; 
			
			messageArea = new TextArea();
			messageArea.percentHeight = 100;
			messageArea.percentWidth = 100;
			
			this.addChild(messageArea);
			
			this.addEventListener(CloseEvent.CLOSE,closeWindowHandler);
		}
		/**
		 * 消息显示对话框 
		 * @param message 显示的消息内容
		 * @param parent  父窗体对象
		 * @param title   标题
		 * 
		 */		
		public function show(message:String,parent:Application,title:String = null):void{
			this.messageArea.text = message;
			if (title != null){
				this.title = title;
			}
			if (this.parent != null){
				parent.removeChild(this);
			}
			var Posx:Number;
			var Posy:Number;
			this.showCloseButton=true;
			
			Posx=(parent.width-this.width)/2;
			Posy=(parent.height-this.height)/2;
			this.x = Posx;
			this.y = Posy;
			
			EDIPopUpManager.addPopUp(this,parent,true);
			
		}
		
		/**
		 *   封装的关闭事件
		 * @param event 类型为：CloseEvent
		 * 
		 */		
		protected function closeWindowHandler(event:CloseEvent):void
		{
			com.edi.runtime.Event.EDIEventProxy.removeListener(this);
			close();
//			this.removeEventListener(CloseEvent.CLOSE,closeWindowHandler);
			//this.removeAllChildren();
		}
		
		/**
		 *  关闭该对话框 
		 * 
		 */		
		public function close():void
		{
			EDIPopUpManager.removePopUp(this);
		}

	}
}